package com.trippin.Utils.unittests;

import static org.junit.Assert.*;



import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

//import com.beoui.geocell.model.Point;
import com.beoui.geocell.model.BoundingBox;
import com.google.appengine.repackaged.org.json.JSONException;
import com.google.appengine.repackaged.org.json.JSONObject;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
//import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.trippin.DB.entities.AttractionEntity;


public class ServletUtilTest {
	
	//@Test //(expected = JsonParseException.class)
	public void writeJSONEntitiesTest() throws JsonParseException, JSONException{
		//Entity entity = new Entity(KeyFactory.createKey("Key", "1"));
		//entity.setProperty("name", "name");
		
		//System.out.println(ServletUtil.writeJSON(entity));
		GsonBuilder gb = new GsonBuilder();
		gb.serializeNulls();//.excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(AttractionEntity.class, new NewAttractionJSONDeserializer());
		Gson gsonNotExclude = gb.create();
		Gson gsonExclude = gb.excludeFieldsWithoutExposeAnnotation().create();
		
		//Point p = new Point(3.2,3.2);	
		
		AttractionEntity att = new AttractionEntity();
		
		att.initNewAttraction(0,30,40);
		att.setTitle("testAttraction");		
		att.addFutureAttendee((long) 1);
		att.addFutureAttendee((long) 23);
		att.addFutureAttendee((long) 124);
		System.out.println(gsonExclude.toJson(att));
		System.out.println(gsonNotExclude.toJson(att));
		
		JSONObject jo = new JSONObject(att);
		jo.put("attend", true);
		System.out.println(jo.toString());
		
		//System.out.println(gson.toJson(longs, List.class));
		
		String attractionJson = "{latitude : 3, longitude : 5, title : hgfdh}";
		att = gsonNotExclude.fromJson(attractionJson,AttractionEntity.class);
		System.out.println(gsonNotExclude.toJson(att));
		
		//System.out.println(Long.parseLong(""));
		
	}
	
	//@Test 
	public void testLongSet() {
		Set<Long> set = new HashSet<Long>();
		set.add((long)120);
		set.add((long)5465476);
		
		long a = 120;
		long b = 5465476;
		assertTrue(set.contains(a));
		assertTrue(set.contains(b));
		
	}
	
	@Test 
	public void testPrimitiveJson() {
		Gson gson = new Gson();
		BoundingBox bb = new BoundingBox(10, 20, 15, 180);
		
		System.out.println(gson.toJson(bb));
		
	}
	
	
	/*
	@Test
	public void SimpleJSONGsonTest() throws ParseException {
		Gson gson = new Gson();
		String corJson = "{ latN : 1, lonE : 2, latS : 3, lonW : 4 }";
		MapSqureCoordinates cors = gson.fromJson(corJson, MapSqureCoordinates.class);
		assertTrue(cors.getLatitudeNorth() == 1);
		assertTrue(cors.getLongitudeEast() == 2);
		assertTrue(cors.getLatitudeSouth() == 3);
		assertTrue(cors.getLongitudeWest() == 4);
		
		corJson = "{ lonE : 2, latS : 3, latN : 1, lonW : 4 }";
		cors = gson.fromJson(corJson, MapSqureCoordinates.class);
		assertTrue(cors.getLatitudeNorth() == 1);
		assertTrue(cors.getLongitudeEast() == 2);
		assertTrue(cors.getLatitudeSouth() == 3);
		assertTrue(cors.getLongitudeWest() == 4);	
	}
		
		
	
	@Test
	public void writeJSONTest() {
		List<MapSqureCoordinates> cors = new ArrayList<MapSqureCoordinates>();
		String corsJson = "{data: [{\"latN\":1.0,\"lonE\":2.0,\"latS\":3.0,\"lonW\":4.0}," +
				"{\"latN\":5.0,\"lonE\":6.0,\"latS\":7.0,\"lonW\":8.0},{\"latN\":9.0,\"lonE\":10.0," +
						"\"latS\":11.0,\"lonW\":12.0}]}";
		cors.add(new MapSqureCoordinates(1,2,3,4));
		cors.add(new MapSqureCoordinates(5,6,7,8));
		cors.add(new MapSqureCoordinates(9,10,11,12));
		assertTrue(corsJson.equals(ServletUtil.getResponseBody(cors, "actionResponse")));
		
		String corJson = "{ actionResponse : actionResponse, " +
				"data: {\"latN\":1.0,\"lonE\":2.0,\"latS\":3.0,\"lonW\":4.0} }";
		String bodyRes = ServletUtil.getResponseBody(new MapSqureCoordinates(1,2,3,4));
		assertTrue(corJson.equals(bodyRes));
		

	}
	*/
}
